<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function(){
            var inputObj = document.getElementById("selectAll");
            var inputArr = document.getElementsByClassName("select");
            inputObj.onclick = function(){
                //监听这个按钮有没有被按
                if(this.checked){
                    //遍历数组给每一个东西设置值
                    for(var i = 0;i<inputArr.length;i++){
                        var inObj = inputArr[i];
                        inObj.checked = true;
                    }
                }else{
                    for(var i = 0;i<inputArr.length;i++){
                        var inObj = inputArr[i];
                        inObj.checked = false;
                }
            }
        }
    }
    </script>
</head>
<body>
    <center>
    <table border="1px" style="width: 600px;">
        <tr>
            <td>
                全选/全不选<input id="selectAll" type="checkbox"/>
            </td>
            <td>学号</td>
            <td>姓名</td>
            <td>年龄</td>
            <td>成绩</td>
        </tr>
        <tr>
            <td>
                <input class="select" type="checkbox"/>
            </td>
            <td>1</td>
            <td>张三</td>
            <td>18</td>
            <td>100</td>
        </tr>
        <tr>
            <td>
                <input class="select" type="checkbox"/>
            </td>
            <td>2</td>
            <td>李四</td>
            <td>20</td>
            <td>90</td>
        </tr>
    </table>
    </center>
</body>
</html>